package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lo
 */
@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "channel",tags = "频道管理",description = "频道管理API")
public class AdChannelController {

    @Autowired
    private AdChannelService adChannelService;
    /**
     * 根据频道名称分页查询频道列表
     * @return
     */
    @ApiOperation("频道分页列表查询")
    @PostMapping("list")
    public ResponseResult getPageList(@RequestBody ChannelDto channelDto){
        return adChannelService.findChannelbyPage(channelDto);
    }

    /**
     * 根据id删除频道信息
     * @param id 前端传递的需要删除数据的id
     * @return
     */
    @ApiOperation("根据id删除频道")
    @GetMapping("/del/{id}")
    public ResponseResult delChannel(@PathVariable Integer id){
        return adChannelService.delChannel(id);
    }

    /**
     * 根据id新增频道信息
     * @param adChannel
     * @return
     */
    @ApiOperation("新增频道信息")
    @PostMapping("/save")
    public ResponseResult saveChannel(@RequestBody AdChannel adChannel){
        return adChannelService.saveChannel(adChannel);
    }

    @ApiOperation("修改频道信息")
    @PostMapping("/update")
    public ResponseResult updateChannel(@RequestBody AdChannel adChannel){
        return adChannelService.updateChannel(adChannel);
    }

    /**
     * 查询所有频道
     *
     */
    @ApiOperation("查询所有频道")
    @GetMapping("/channels")
    public ResponseResult getChannelList( ){
        List<AdChannel> list = adChannelService.list();
        return ResponseResult.okResult(list);
    }

    @ApiOperation("根据id查询频道")
    @GetMapping("/one/{id}")
    public ResponseResult findOne(@PathVariable Integer id) {

        return ResponseResult.okResult(adChannelService.getById(id));
    }

}
